//
//  UIImage+Extension.swift
//  YANAWeibo
//
//  Created by mac on 16/5/21.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

extension UIImage {
    // 等比压缩图片
    func scaleImageWithWidth(scaleWidth: CGFloat) -> UIImage {
        let scaleHeight = scaleWidth / self.size.width * self.size.height
        
        let size = CGSize(width: scaleWidth, height: scaleHeight)
        // 开启上下文
        UIGraphicsBeginImageContext(size)
        // 绘制图片
        self.drawInRect(CGRect(origin: CGPointZero, size: size))
        // 获得压缩图片
         let scaleImage = UIGraphicsGetImageFromCurrentImageContext()
        // 关闭上下文
        UIGraphicsEndImageContext()
        
        return scaleImage
    }
}
